/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function refresh_chat(receiver, sender) {
	//Create request
	var request = new XMLHttpRequest();

	//Add to chat window if done
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200)
			document.getElementById("chat-window").innerHTML += request.responseText;
	}

	//Send request
	request.open("POST", "/deviantpic/service/chat.php", true);
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.send("action=receive&receiver=" + receiver + "&sender=" + sender);

	//Set timeout
	setTimeout("refresh_chat(" + receiver + ", " + sender + ")", 5000);
}

function send_chat(element, sender, receiver) {
	//Get string inside the element
	Message = document.getElementById(element).value;
	if (Message == "") return;

	//Create request
	var request = new XMLHttpRequest();

	//Add to chat window if done
	request.onreadystatechange = function() {
		if (request.readyState == 4 && request.status == 200)
			document.getElementById("chat-window").innerHTML += request.responseText;
	}

	//Send request
	request.open("POST", "/deviantpic/service/chat.php", true);
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.send("action=send&receiver=" + receiver + "&sender=" + sender + " &message=" + escape(Message));
}